package com.mzj.saas.jobs.lock.service;

import com.mzj.saas.commons.enums.LockOperatorTypeEnum;
import com.mzj.saas.jobs.bill.entity.SmartLockBle;
import com.mzj.saas.jobs.bill.entity.SmartLockCard;
import com.mzj.saas.jobs.bill.entity.SmartLockFace;
import com.mzj.saas.jobs.bill.entity.SmartLockPwd;
import com.mzj.saas.jobs.bill.repository.SmartLockCardRepository;
import com.mzj.saas.jobs.bill.repository.SmartLockPwdRepository;
import com.mzj.saas.jobs.commons.ResultBean;
import com.mzj.saas.jobs.commons.StatusCode;
import com.mzj.saas.jobs.lock.service.haixiaoke.SmartLockHxkService;
import com.mzj.saas.jobs.lock.service.huixiangjia.SmartLockHxjService;
import com.mzj.saas.jobs.lock.service.luoke.SmartLockLkService;
import com.mzj.saas.jobs.lock.service.ruanku.SmartLockService;
import com.mzj.saas.jobs.lock.service.xizhao.SmartLockXzService;
import com.mzj.saas.jobs.lock.service.yaluete.SmartLockYltService;
import com.mzj.saas.jobs.lock.vo.DevMacStateVO;
import com.mzj.saas.jobs.lock.vo.DynamicPasswordVO;
import com.mzj.saas.jobs.lock.vo.SmartLockFingerprintVO;
import com.mzj.saas.jobs.lock.vo.yaluete.SmartLockVO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Date;
import java.util.List;

/**
 * 不同品牌智能锁接口
 *
 * @author shun
 * @createDate: 2021年6月25日 下午4:45:44
 * @version: 1.0
 *
 */
@Service
public class SmartLockBrandService {

	private static final Logger log = LoggerFactory.getLogger(SmartLockBrandService.class);

	@Autowired
	private SmartLockService smartLockService;
	@Autowired
	private SmartLockXzService smartLockXzService;
	@Autowired
	private SmartLockXzService smartLockApiService;
	@Autowired
	private SmartLockYltService smartLockYltService;
	@Autowired
	private SmartLockHxkService smartLockHxkService;
	@Autowired
	private SmartLockLkService smartLockLkService;
	@Autowired
	private SmartLockPwdRepository smartLockPwdRepository;
	@Autowired
	private SmartLockCardRepository smartLockCardRepository;
	@Autowired
	private SmartLockHxjService smartLockHxjService;

	/**
	 * 根据mac获取设备sn号/熙照设备注册
	 *
	 * @param devMac
	 *            设备MAC
	 * @param brandId
	 *            设备品牌id
	 * @return
	 * @author shun
	 * @date 2021年6月25日
	 */
	public ResultBean<String> getSnByMac(String devMac, String deviceName, Long brandId) {
		try {
			if (StringUtils.isBlank(devMac) || brandId == null) {
				return ResultBean.failedResultOfParamWithMsg("参数错误");
			}

			switch (brandId.toString()) {
			case "1":
				// 软库智能锁
				return smartLockService.getSnByMac(devMac);
			case "2":
				// 熙照智能锁(无需获取SN), 此处调用注册接口, 成功后返回的sn = imei
				// 熙照智能锁注册(没有查询sn接口，注册后事件返回sn，事件中会更新表sn字段)
				// 注册后返回sn为空
				return smartLockApiService.bindimei(devMac, deviceName, brandId);
			case "3":
				// 亚略特无需SN，所有接口操作使用MAC = imei号
				return smartLockYltService.merchantinfoBindLock(devMac, brandId);
			default:
				break;
			}
		} catch (Exception e) {
			log.error("根据mac获取设备sn号异常" + e.getMessage(), e);
		}

		return ResultBean.failedResultOfException();
	}



	/**
	 * 获取锁状态
	 *
	 * @param id
	 *            锁SN或锁ID
	 * @param brandId
	 *            设备品牌id
	 * @return
	 * @author shun
	 * @date 2021年6月25日
	 */
	public ResultBean<DevMacStateVO> getState(String id, Long brandId) {
		try {
			if (StringUtils.isBlank(id) || brandId == null) {
				return ResultBean.failedResultOfParamWithMsg("参数错误");
			}

			switch (brandId.toString()) {
			case "1":
				// 软库智能锁
				return smartLockService.getState(id);
			case "2":
				// 熙照
				return smartLockXzService.getState(id, brandId);
			case "3":
				// 亚略特无此接口
			default:
				break;
			}
		} catch (Exception e) {
			log.error("获取锁状态异常" + e.getMessage(), e);
		}
		return ResultBean.failedResultOfException();
	}

	/**
	 * 批量获取锁状态
	 *
	 * @param
	 * @return
	 */
	public ResultBean<List<DevMacStateVO>> batchGetState(List<String> sns, Long brandId) {
		try {
			if (CollectionUtils.isEmpty(sns) || brandId == null) {
				return ResultBean.failedResultOfParamWithMsg("参数错误");
			}

			switch (brandId.toString()) {
			case "1":
				// 软库智能锁
				return smartLockService.batchGetState(sns);
			case "2":
				//
				// TODO

				break;
			case "3":
				// 亚略特无此接口
				break;
			default:
				break;
			}
		} catch (Exception e) {
			log.error("批量获取锁状态异常" + e.getMessage(), e);
		}
		return ResultBean.failedResultOfException();
	}

	/**
	 * 查询动态密码
	 *
	 * @param vo
	 * @return
	 */
	public ResultBean<List<DynamicPasswordVO>> getDynamicPassword(SmartLockVO vo, Long brandId) {
		try {
			if (brandId == null) {
				return ResultBean.failedResultOfParamWithMsg("参数错误");
			}

			switch (brandId.toString()) {
			case "1":
				return smartLockService.getDynamicPassword(vo);
			case "2":
				return smartLockXzService.getDynamicPassword(vo.getSn(), brandId);
			case "3":
				// 暂时厂家未开通
				return smartLockYltService.getUrgentPassword(vo.getSn(), brandId);
			default:
				break;
			}
		} catch (Exception e) {
			log.error("查询动态密码异常" + e.getMessage(), e);
		}
		return ResultBean.failedResultOfException();
	}

	/**
	 * 新增/修改密码
	 *
	 * @param vo
	 * @param smartLockPwd
	 * @param brandId
	 * @return
	 * @author shun
	 * @date 2021年7月6日
	 */
	public ResultBean<String> operationPassword(SmartLockVO vo, SmartLockPwd smartLockPwd, Long brandId) {
		try {
			if (brandId == null) {
				return ResultBean.failedResultOfParamWithMsg("参数错误");
			}

			switch (brandId.toString()) {
			case "1":
				return smartLockService.operationPassword(vo);
			case "2":
				return smartLockXzService.validateOperationTypeAndPassword(smartLockPwd, vo, brandId);
			case "3":

				SmartLockPwd smartLockPwds = null;
				if (smartLockPwd != null || smartLockPwd.getId() != null) {
					smartLockPwds = smartLockPwdRepository.findByLockAuthId(smartLockPwd.getLockAuthId());

				}

				Date date = new Date();
				long time = date.getTime();

				// 新增
				if (smartLockPwd == null || smartLockPwd.getId() == null) {
					// 必须设置YltAuthorizationVO参数值
					return smartLockYltService.lockAuthorization(brandId, vo);
				}else if (smartLockPwds.getEndTime() == null || time > smartLockPwds.getEndTime().getTime()){
					ResultBean<String> stringResultBean = smartLockYltService.lockAuthorization(brandId, vo);
					String resultData = stringResultBean.getResultData();
					String msg = stringResultBean.getMsg();
					String code = stringResultBean.getCode();

					if (!code.equals(StatusCode.SUCCESS_CODE_10000.getErrorCode())) {
						log.error("operationPassword authPwd 更新亚略特授权ID失败---> " + msg);
						return ResultBean.failedResultWithCodeAndMsg(code, msg);
					}else {
						log.info("operationPassword authPwd 更新亚略特授权ID成功---> callBack={}", resultData);
						// 更新密码授权ID
						smartLockPwd.setfAuthorizationId(resultData);

					}

				}else if (smartLockPwd.getId() != null) {
					// 修改
					if ("5".equals(vo.getAuthType())) {
						return ResultBean.failedResultOfParamWithMsg("设备不支持修改次数");
					}
					// 只能更新密码
					return smartLockYltService.updateAuthorize(vo, brandId);
				}

			default:
				break;
			}
		} catch (Exception e) {
			log.error("新增/修改密码异常" + e.getMessage(), e);
		}
		return ResultBean.failedResultOfException();
	}

	/**
	 * 冻结/解冻密码
	 *
	 * @param vo
	 * @param brandId
	 * @param operatorType
	 *            1密码 2卡 3指纹
	 * @return
	 * @author shun
	 * @date 2021年9月15日
	 */
	public ResultBean<String> freezeOrUnfreeze(SmartLockVO vo, Long brandId, Integer operatorType) {
		try {
			if (brandId == null) {
				return ResultBean.failedResultOfParamWithMsg("参数错误");
			}

			switch (brandId.toString()) {
			case "1":
				return smartLockService.freezeOrUnfreeze(vo);
			case "2":
				// 熙照智能锁, 1密码 2卡 3指纹
				return smartLockXzService.freezeOrUnfreeze(vo, brandId, operatorType);
			case "3":
				// 亚略特智能锁，没有冻结操作，只能做取消授权
				// 冻结（1）或者解冻（0)
				if(vo.getSuspend() == 1){
					// 取消授权
					return smartLockYltService.deauthorize(vo, brandId, LockOperatorTypeEnum.GENERAL_UN_AUTH.getValue());
				}else{
					// 授权，返回授权后新的AuthorizationID，需要同步更新到授权表中
					return smartLockYltService.lockAuthorization(brandId, vo);
				}
				/*case "4":
					// 天网互联，删除授权密码
					// 冻结（1）或者解冻（0)
					if (vo.getSuspend() == 1) {
						return smartLockTWHlService.deletePwd(vo, vo.getAuthInfoId());
					} else {
						// 天网互联，授权密码
						Long authInfoId = vo.getAuthInfoId();
						Integer pwdType = vo.getPwdType();
						SmartLockPwd smartLockPwd = smartLockPwdRepository.findByLockAuthIdAndType(authInfoId, pwdType);

						return smartLockTWHlService.authorizationPwd(vo, smartLockPwd);
					}*/
				case "5":
					// 嗨小克，删除授权密码
					// 冻结（1）或者解冻（0)
					if (vo.getSuspend() == 1) {
						return smartLockHxkService.deletePwd(vo, vo.getAuthInfoId());
					} else {
						// 嗨小克，授权密码
						Long authInfoId = vo.getAuthInfoId();
						Integer pwdType = vo.getPwdType();
						SmartLockPwd smartLockPwd = smartLockPwdRepository.findByLockAuthIdAndType(authInfoId, pwdType);

						return smartLockHxkService.authorizationPwd(vo, smartLockPwd);
					}
				/*case "6":
					// 优电，删除授权密码
					// 冻结（1）或者解冻（0)
					if (vo.getSuspend() == 1) {
						return smartLockYdService.deletePwd(vo, vo.getAuthInfoId());
					} else {
						// 优电，授权密码
						Long authInfoId = vo.getAuthInfoId();
						Integer pwdType = vo.getPwdType();
						SmartLockPwd smartLockPwd = smartLockPwdRepository.findByLockAuthIdAndType(authInfoId, pwdType);

						return smartLockYdService.authorizationPwd(vo, smartLockPwd);
					}*/
				case "7":
					// 络克，删除授权密码
					// 冻结（1）或者解冻（0)
					//状态true：启用false：禁用
					boolean stateFlag = vo.getSuspend() != 1;
					return smartLockLkService.updateKeyState(vo.getIdentification(),stateFlag);
					/*if (vo.getSuspend() == 1) {
						return smartLockLkService.deletePwd(vo, vo.getAuthInfoId());
					} else {
						// 络克，授权密码
						Long authInfoId = vo.getAuthInfoId();
						Integer pwdType = vo.getPwdType();
						SmartLockPwd smartLockPwd = smartLockPwdRepository.findByLockAuthIdAndType(authInfoId, pwdType);

						return smartLockLkService.authorizationPwd(vo, smartLockPwd);
					}*/
				case "8":
					//慧享佳，删除授权密码
					if (vo.getSuspend() == 1) {
						return smartLockHxjService.deletePwd(vo, vo.getAuthInfoId());
					} else {
						// 慧享佳，授权密码
						Long authInfoId = vo.getAuthInfoId();
						Integer pwdType = vo.getPwdType();
						SmartLockPwd smartLockPwd = smartLockPwdRepository.findByLockAuthIdAndType(authInfoId, pwdType);
						return smartLockHxjService.authorizationPwd(vo, smartLockPwd);
					}
			default:
				break;
			}
		} catch (Exception e) {
			log.error("冻结/解冻密码异常" + e.getMessage(), e);
		}
		return ResultBean.failedResultOfException();
	}

	/**
	 * 删除密码
	 *
	 * @param vo
	 * @return 回调id
	 */
	public ResultBean<String> clearPassword(SmartLockVO vo, Long brandId, String passwordType) {
		try {
			//校验品牌参数
			if (brandId == null) {
				return ResultBean.failedResultOfParamWithMsg("参数错误");
			}

			switch (brandId.toString()) {
			case "1":
				return smartLockService.clearPassword(vo);
			case "2":
				// code 密码 adminpwd 管理员密码(删除不支持)
				// dynamicpwd 动态密码(冻结、解冻、删除不支持)
				// fingerprint 指纹
				// card 卡片
				return smartLockXzService.clearPassword(vo, brandId, passwordType);
			case "3":
				// 亚略特只有取消授权
				return smartLockYltService.deauthorize(vo, brandId, LockOperatorTypeEnum.GENERAL_UN_AUTH.getValue());
			default:
				break;
			}
		} catch (Exception e) {
			log.error("删除密码异常" + e.getMessage(), e);
		}
		return ResultBean.failedResultOfException();
	}

	/**
	 * 清除锁所有密码(不包含动态密码（动态密码可以继续使用）。)
	 *
	 * @param vo
	 * @return 回调id
	 */
	public ResultBean<String> clearAllPassword(@RequestBody SmartLockVO vo, Long brandId) {
		try {
			if (brandId == null) {
				return ResultBean.failedResultOfParamWithMsg("参数错误");
			}

			switch (brandId.toString()) {
			case "1":
				return smartLockService.clearAllPassword(vo);
			case "2":
				//
				// TODO

				break;
			case "3":
				break;
			default:
				break;
			}
		} catch (Exception e) {
			log.error("清除锁所有密码异常" + e.getMessage(), e);
		}
		return ResultBean.failedResultOfException();
	}

	/**
	 * 新增/修改卡
	 *
	 * @param vo
	 * @return 回调id
	 */
	public ResultBean<String> operationCardPassword(SmartLockVO vo, SmartLockCard smartLockCard, Long brandId) {
		try {
			if (brandId == null) {
				return ResultBean.failedResultOfParamWithMsg("参数错误");
			}

			switch (brandId.toString()) {
			case "1":
				// 软库
				return smartLockService.operationCardPassword(vo);
			case "2":
				// 熙照
				return smartLockXzService.validateOperationTypeAndCardPwd(smartLockCard, vo, brandId);
			case "3":
				// 亚略特
				// 新增
				if (smartLockCard.getId() == null) {
					// 必须设置YltAuthorizationVO参数值
					return smartLockYltService.lockAuthorization(brandId, vo);
				}

				// 次数不能修改
				if ("5".equals(vo.getAuthType())) {
					return ResultBean.failedResultOfParamWithMsg("设备不支持修改次数");
				}

				/**
				 * 不支持卡更新，只能删除卡重新授权
				 */

				// 取消授权
				smartLockYltService.deauthorize(vo, brandId, LockOperatorTypeEnum.GENERAL_UN_AUTH.getValue());

				// 授权，返回授权后新的AuthorizationID，需要同步更新到授权表中
				return smartLockYltService.lockAuthorization(brandId, vo);
			default:
				break;
			}
		} catch (Exception e) {
			log.error("新增/修改卡异常" + e.getMessage(), e);
		}
		return ResultBean.failedResultOfException();
	}

	/**
	 * 冻结/解冻卡
	 *
	 * @param vo
	 * @param brandId
	 * @param operatorType
	 *            熙照智能锁, 1密码 2卡 3指纹
	 * @return
	 * @author shun
	 * @date 2021年7月2日
	 */
	public ResultBean<String> freezeOrUnfreezeCard(SmartLockVO vo, Long brandId, Integer operatorType) {
		try {
			if (brandId == null) {
				return ResultBean.failedResultOfParamWithMsg("参数错误");
			}

			switch (brandId.toString()) {
			case "1":
				return smartLockService.freezeOrUnfreezeCard(vo);
			case "2":
				return smartLockXzService.freezeOrUnfreeze(vo, brandId, operatorType);
			case "3":
				// 亚略特智能锁，没有冻结操作，只能做取消授权
				// 冻结（1）或者解冻（0)
				if(vo.getSuspend() == 1){
					// 取消授权
					return smartLockYltService.deauthorize(vo, brandId, LockOperatorTypeEnum.GENERAL_UN_AUTH.getValue());
				}else{
					// 授权，返回授权后新的AuthorizationID，需要同步更新到授权表中
					return smartLockYltService.lockAuthorization(brandId, vo);
				}
				/*case "4":
					// 天网互联，没有冻结操作，只能做取消授权
					// 冻结（1）或者解冻（0)
					if (vo.getSuspend() == 1) {
						// 天网互联删除身份证/CPU卡开锁
						return smartLockTWHlService.deleteIdentityCardUnlocking(vo);
					} else {
						// 天网互联授权身份证/CPU卡开锁
						Long authInfoId = vo.getAuthInfoId();
						Integer cardType = vo.getCardType();
						SmartLockCard smartLockCard = smartLockCardRepository.findByLockAuthIdAndType(authInfoId, cardType);
						return smartLockTWHlService.identityCardUnlocking(vo, smartLockCard);
					}*/
				case "5":
					// 嗨小克，没有冻结操作，只能做取消授权
					// 冻结（1）或者解冻（0)
					if (vo.getSuspend() == 1) {
						// 天网互联删除身份证/CPU卡开锁
						return smartLockHxkService.deleteIdentityCardUnlocking(vo);
					} else {
						// 嗨小克授权身份证/CPU卡开锁
						Long authInfoId = vo.getAuthInfoId();
						Integer cardType = vo.getCardType();
						SmartLockCard smartLockCard = smartLockCardRepository.findByLockAuthIdAndType(authInfoId, cardType);
						return smartLockHxkService.identityCardUnlocking(vo, smartLockCard);
					}
				/*case "6":
					// 优电，没有冻结操作，只能做取消授权
					// 冻结（1）或者解冻（0)
					if (vo.getSuspend() == 1) {
						// 优电删除身份证/CPU卡开锁
						return smartLockYdService.deleteIdentityCardUnlocking(vo);
					} else {
						// 优电授权身份证/CPU卡开锁
						Long authInfoId = vo.getAuthInfoId();
						Integer cardType = vo.getCardType();
						SmartLockCard smartLockCard = smartLockCardRepository.findByLockAuthIdAndType(authInfoId, cardType);
						return smartLockYdService.identityCardUnlocking(vo, smartLockCard);
					}*/
				case "7":
					// 络克，没有冻结操作，只能做取消授权
					// 冻结（1）或者解冻（0)
					//状态true：启用false：禁用
					boolean stateFlag = vo.getSuspend() != 1;
					return smartLockLkService.updateKeyState(vo.getIdentification(),stateFlag);
					/*if (vo.getSuspend() == 1) {
						// 天网互联删除身份证/CPU卡开锁
						return smartLockLkService.deleteIdentityCardUnlocking(vo);
					} else {
						// 络克，授权身份证/CPU卡开锁
						Long authInfoId = vo.getAuthInfoId();
						Integer cardType = vo.getCardType();
						SmartLockCard smartLockCard = smartLockCardRepository.findByLockAuthIdAndType(authInfoId, cardType);
						return smartLockLkService.identityCardUnlocking(vo, smartLockCard);
					}*/
				case "8":
					// 慧享佳，没有冻结操作，只能做取消授权
					if (vo.getSuspend() == 1) {
						// 慧享佳删除身份证/CPU卡开锁
						return smartLockHxjService.deleteIdentityCardUnlocking(vo);
					} else {
						// 慧享佳授权身份证/CPU卡开锁
						Long authInfoId = vo.getAuthInfoId();
						Integer cardType = vo.getCardType();
						SmartLockCard smartLockCard = smartLockCardRepository.findByLockAuthIdAndType(authInfoId, cardType);
						return smartLockHxjService.identityCardUnlocking(vo, smartLockCard);
					}
			default:
				break;
			}
		} catch (Exception e) {
			log.error("冻结/解冻卡异常" + e.getMessage(), e);
		}
		return ResultBean.failedResultOfException();
	}

	/**
	 * 删除卡
	 *
	 * @param vo
	 * @return 回调id
	 */
	public ResultBean<String> clearCard(SmartLockVO vo, Long brandId, String passwordType) {
		try {
			if (brandId == null) {
				return ResultBean.failedResultOfParamWithMsg("参数错误");
			}

			switch (brandId.toString()) {
			case "1":
				return smartLockService.clearCard(vo);
			case "2":
				// code 密码 adminpwd 管理员密码(删除不支持)
				// dynamicpwd 动态密码(冻结、解冻、删除不支持)
				// fingerprint 指纹
				// card 卡片
				return smartLockXzService.clearPassword(vo, brandId, passwordType);
			case "3":
				// 亚略特只有取消授权
				return smartLockYltService.deauthorize(vo, brandId, LockOperatorTypeEnum.GENERAL_UN_AUTH.getValue());
			default:
				break;
			}
		} catch (Exception e) {
			log.error("删除卡异常" + e.getMessage(), e);
		}
		return ResultBean.failedResultOfException();
	}

	/**
	 * 删除所有卡
	 *
	 * @param vo
	 * @return 回调id
	 */
	public ResultBean<String> clearAllCard(@RequestBody SmartLockVO vo, Long brandId) {
		try {
			if (brandId == null) {
				return ResultBean.failedResultOfParamWithMsg("参数错误");
			}

			switch (brandId.toString()) {
			case "1":
				return smartLockService.clearAllCard(vo);
			case "2":
				//
				// TODO

				break;
			case "3":
				break;
			default:
				break;
			}
		} catch (Exception e) {
			log.error("删除所有卡异常" + e.getMessage(), e);
		}
		return ResultBean.failedResultOfException();
	}

	/**
	 * 指纹新增/修改
	 *
	 * @param vo
	 * @return 回调id
	 */
	public ResultBean<String> operationFingerprint(SmartLockFingerprintVO vo, Long fingerprintId, Long brandId) {
		try {
			if (brandId == null) {
				return ResultBean.failedResultOfParamWithMsg("参数错误");
			}

			switch (brandId.toString()) {
			case "1":
				// 软库
				return ResultBean.failedResultOfParamWithMsg("设备不支持");
			case "2":
				// 熙照
				return smartLockXzService.validateOperationFingerprint(vo, fingerprintId, brandId);
			case "3":
				// 亚略特
				// 新增
				SmartLockVO cvLockVO = new SmartLockVO();
				cvLockVO.setYltAuth(vo.getYltAuth());
				if (fingerprintId == null) {
					// 授权，返回授权后新的AuthorizationID，需要同步更新到授权表中
					return smartLockYltService.lockAuthorization(brandId, cvLockVO);
				}

				// 次数不能修改
				if ("5".equals(vo.getAuthType())) {
					return ResultBean.failedResultOfParamWithMsg("设备不支持修改次数");
				}

				/**
				 * 不支持卡更新，只能删除卡重新授权
				 */
				// 取消授权
				cvLockVO.setSn(vo.getSn());
				cvLockVO.setfAuthorizationID(vo.getfAuthorizationID());
				smartLockYltService.deauthorize(cvLockVO, brandId, LockOperatorTypeEnum.GENERAL_UN_AUTH.getValue());

				// 授权，返回授权后新的AuthorizationID，需要同步更新到授权表中
				return smartLockYltService.lockAuthorization(brandId, cvLockVO);
			default:
				break;
			}
		} catch (Exception e) {
			log.error("新增指纹异常" + e.getMessage(), e);
		}
		return ResultBean.failedResultOfException();
	}

	/**
	 * 删除指纹
	 *
	 * @param vo
	 * @param brandId
	 * @param passwordType
	 * @return
	 * @author shun
	 * @date 2021年7月7日
	 */
	public ResultBean<String> clearFingerprint(SmartLockVO vo, Long brandId, String passwordType) {
		try {
			if (brandId == null) {
				return ResultBean.failedResultOfParamWithMsg("参数错误");
			}

			switch (brandId.toString()) {
			case "1":
				return ResultBean.failedResultOfParamWithMsg("设备不支持");
			case "2":
				// code 密码 adminpwd 管理员密码(删除不支持)
				// dynamicpwd 动态密码(冻结、解冻、删除不支持)
				// fingerprint 指纹
				// card 卡片
				return smartLockXzService.clearPassword(vo, brandId, passwordType);
			case "3":
				// 取消授权
				return smartLockYltService.deauthorize(vo, brandId, LockOperatorTypeEnum.GENERAL_UN_AUTH.getValue());
			default:
				break;
			}
		} catch (Exception e) {
			log.error("删除卡异常" + e.getMessage(), e);
		}
		return ResultBean.failedResultOfException();
	}

	/**
	 * 冻结/解冻指纹
	 *
	 * @param vo
	 * @param brandId
	 * @param operatorType
	 *            熙照智能锁, 1密码 2卡 3指纹
	 * @return
	 * @author shun
	 * @date 2021年7月2日
	 */
	public ResultBean<String> freezeOrUnfreezeFingerprint(SmartLockVO vo, Long brandId, Integer operatorType) {
		try {
			if (brandId == null) {
				return ResultBean.failedResultOfParamWithMsg("参数错误");
			}

			switch (brandId.toString()) {
			case "1":
				break;
			case "2":
				return smartLockXzService.freezeOrUnfreeze(vo, brandId, operatorType);
			case "3":
				// 亚略特智能锁，没有冻结操作，只能做取消授权
				// 冻结（1）或者解冻（0)
				if(vo.getSuspend() == 1){
					// 取消授权
					return smartLockYltService.deauthorize(vo, brandId, LockOperatorTypeEnum.GENERAL_UN_AUTH.getValue());
				}else{
					// 授权，返回授权后新的AuthorizationID，需要同步更新到授权表中
					return smartLockYltService.lockAuthorization(brandId, vo);
				}
			default:
				break;
			}
		} catch (Exception e) {
			log.error("冻结/解冻卡异常" + e.getMessage(), e);
		}
		return ResultBean.failedResultOfException();
	}

	/**
	 * 授权蓝牙
	 * @param vo
	 * @param smartLockBle
	 * @param brandId
	 * @return
	 */
	public ResultBean<String> operationBle(SmartLockVO vo, SmartLockBle smartLockBle , Long brandId) {
		try {
			if (brandId == null) {
				return ResultBean.failedResultOfParamWithMsg("参数错误");
			}

			switch (brandId.toString()) {
				case "1":
					// 软库
					return ResultBean.failedResultOfParamWithMsg("设备不支持");
				case "2":
					// 熙照
					return ResultBean.failedResultOfParamWithMsg("设备不支持");
				case "3":
					// 亚略特
					// 新增
					if (smartLockBle.getId() == null) {
						// 必须设置YltAuthorizationVO参数值
						return smartLockYltService.lockAuthorization(brandId, vo);
					}

					// 次数不能修改
					if ("5".equals(vo.getAuthType())) {
						return ResultBean.failedResultOfParamWithMsg("设备不支持修改次数");
					}

					//不支持蓝牙更新，只能删除重新授权
					// 取消授权
					smartLockYltService.deauthorize(vo, brandId, LockOperatorTypeEnum.GENERAL_UN_AUTH.getValue());

					// 授权，返回授权后新的AuthorizationID，需要同步更新到授权表中
					return smartLockYltService.lockAuthorization(brandId, vo);
				default:
					break;
			}
		} catch (Exception e) {
			log.error("新增蓝牙异常" + e.getMessage(), e);
		}
		return ResultBean.failedResultOfException();
	}

	/**
	 * 删除蓝牙授权
	 * @param vo
	 * @param brandId
	 * @return
	 */
	public ResultBean<String> clearBle(SmartLockVO vo, Long brandId) {
		try {
			if (brandId == null) {
				return ResultBean.failedResultOfParamWithMsg("参数错误");
			}

			switch (brandId.toString()) {
				case "1":
					return ResultBean.failedResultOfParamWithMsg("设备不支持");
				case "2":
					return ResultBean.failedResultOfParamWithMsg("设备不支持");
				case "3":
					// 取消授权
					return smartLockYltService.deauthorize(vo, brandId, LockOperatorTypeEnum.GENERAL_UN_AUTH.getValue());
				default:
					break;
			}
		} catch (Exception e) {
			log.error("删除蓝牙异常" + e.getMessage(), e);
		}
		return ResultBean.failedResultOfException();
	}

	/**
	 * 冻结/解冻蓝牙
	 * @param vo
	 * @param brandId
	 * @return
	 */
	public ResultBean<String> freezeOrUnfreezeBle(SmartLockVO vo, Long brandId) {
		try {
			if (brandId == null) {
				return ResultBean.failedResultOfParamWithMsg("参数错误");
			}

			switch (brandId.toString()) {
				case "1":
					break;
				case "2":
					break;
				case "3":
					// 亚略特智能锁，没有冻结操作，只能做取消授权
					// 冻结（1）或者解冻（0)
					if(vo.getSuspend() == 1){
						// 取消授权
						return smartLockYltService.deauthorize(vo, brandId, LockOperatorTypeEnum.GENERAL_UN_AUTH.getValue());
					}else{
						// 授权，返回授权后新的AuthorizationID，需要同步更新到授权表中
						return smartLockYltService.lockAuthorization(brandId, vo);
					}
				case "8":
					//    慧享佳无需授权
					return ResultBean.successfulResult("成功");
				default:
					break;
			}
		} catch (Exception e) {
			log.error("冻结/解冻卡异常" + e.getMessage(), e);
		}
		return ResultBean.failedResultOfException();
	}

	public ResultBean<String> freezeOrUnfreezeFace(SmartLockVO vo, SmartLockFace face, Long brandId) {
		try {
			if (brandId == null) {
				return ResultBean.failedResultOfParamWithMsg("参数错误");
			}

			switch (brandId.toString()) {
				case "1":
					break;
				case "2":
					break;
				case "3":
					break;
				case "4":
					break;
				case "5":
					// 冻结（1）或者解冻（0)
					if (vo.getSuspend() == 1) {
						//嗨小克删除人脸开锁
						return smartLockHxkService.deleteFaceImage(face);
					} else {
						//嗨小克授权人脸开锁
						return smartLockHxkService.addFaceImage(face);
					}
			/*	case "6":
					// 冻结（1）或者解冻（0)
					if (vo.getSuspend() == 1) {
						//优电删除人脸开锁
						return smartLockYdService.deleteFaceImage(face);
					} else {
						//优电授权人脸开锁
						return smartLockYdService.addFaceImage(face);
					}*/
				case "7":
					// 冻结（1）或者解冻（0)
					//状态true：启用false：禁用
					boolean stateFlag = vo.getSuspend() != 1;
					return smartLockLkService.updateKeyState(vo.getIdentification(),stateFlag);
					/*if (vo.getSuspend() == 1) {
						//嗨小克删除人脸开锁
						return smartLockLkService.deleteFaceImage(face);
					} else {
						//嗨小克授权人脸开锁
						return smartLockLkService.addFaceImage(face);
					}*/
				case "8":
					// 冻结（1）或者解冻（0)
					if (vo.getSuspend() == 1) {
						//慧享佳删除人脸开锁
						return smartLockHxjService.deleteFaceImage(face);
					} else {
						//慧享佳授权人脸开锁
						return smartLockHxjService.addFaceImage(face);
					}
				default:
					break;
			}

		} catch (Exception e) {
			log.error("冻结/解冻人脸异常" + e.getMessage(), e);
		}
		return ResultBean.failedResultOfException();


	}

}